﻿using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using Microsoft.Commerce.Proxy.PaymentInstrumentService;

namespace TestWebApplication.CommercePaymentInstrument.APIs
{
    public class CommerceGetPaymentInstrumentApi : CommercePaymentInstrumentApi
    {
        private GetPaymentInstrumentsInput input;
        private GetPaymentInstrumentsOutput output;

        private string paymentMethodId;
        private CallerInfo callerInfo;

        public CommerceGetPaymentInstrumentApi(BasicHttpBinding binding, EndpointAddress address, X509Certificate2 clientCert, CallerInfo callerInfo, string paymentMethodId)
            : base(binding, address, clientCert)
        {
            this.callerInfo = callerInfo;
            this.paymentMethodId = paymentMethodId;
        }

        public PaymentInstrument[] PaymentInstrumentSet { get; private set; }

        protected override AbstractResponse ExecuteInternal(PaymentInstrumentServiceChannel channel)
        {
            this.output = channel.GetPaymentInstruments(this.input);

            return this.output;
        }

        public override void PrepareRequestData()
        {
            this.input = new GetPaymentInstrumentsInput()
            {
                APIContext = new APIContext()
                {
                    TrackingGuid = this.trackingGuid,
                },
                CallerInfo = this.callerInfo,
                PaymentMethodID = this.paymentMethodId
            };
        }

        public override void PrepareResponseData()
        {
            this.PaymentInstrumentSet = this.output.PaymentInstrumentSet;
        }
    }
}
